package com.bkgy.controller.frsaHistory.controller;

import com.alibaba.fastjson.JSONObject;
import com.bkgy.controller.frsaHistory.entity.RealDataDic;
import com.bkgy.controller.frsaHistory.entity.dto.FrsaCharReq;
import com.bkgy.controller.frsaHistory.entity.dto.FrsaHistoryReq;
import com.bkgy.controller.frsaHistory.service.IFrsaHistoryService;
import com.bkgy.sys.common.entity.ResultData;
import com.bkgy.util.DateUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.Date;

@Tag(name = "1630炉辊打滑")
@Controller
@RequestMapping("/frsaHistory")
@RequiredArgsConstructor
public class FrsaHistoryController {
    private final IFrsaHistoryService service;

    @ResponseBody
    @Operation(summary = "辊号打滑频次统计")
    @PostMapping("/rollFreChar")
    public ResultData<JSONObject> rollFreChar(@RequestBody @Valid FrsaCharReq obj) {
        if ("month".equals(obj.getDateType())) {
            obj.setBeginDate(DateUtil.thisMonthFirstDay("yyyy-MM-dd"));
        } else {
            String beginDate = DateUtil.getDateToString(DateUtil.getCurrentZero(new Date()), "yyyy-MM-dd");
            obj.setBeginDate(beginDate);
        }
        return service.rollFreChar(obj);
    }

    @ResponseBody
    @Operation(summary = "区域打滑频次统计")
    @PostMapping("/areaFreChar")
    public ResultData<JSONObject> areaFreChar() {
        return service.areaFreChar();
    }

    @ResponseBody
    @Operation(summary = "钢牌号打滑频次统计")
    @PostMapping("/frsaChar")
    public ResultData<JSONObject> frsaChar(@RequestBody @Valid FrsaCharReq obj) {
        if ("day".equals(obj.getDateType())) {
            String beginDate = DateUtil.getDateToString(DateUtil.getCurrentZero(new Date()), "yyyyMMdd");
            obj.setBeginDate(beginDate);
            obj.setEndDate(DateUtil.nextMonthFirstDay("yyyyMMdd"));
        } else if ("week".equals(obj.getDateType())) {
            obj.setBeginDate(DateUtil.thisWeekFirstDay("yyyyMMdd"));
            obj.setEndDate(DateUtil.nextMonthFirstDay("yyyyMMdd"));
        } else if ("month".equals(obj.getDateType())) {
            obj.setBeginDate(DateUtil.thisMonthFirstDay("yyyyMMdd"));
            obj.setEndDate(DateUtil.nextMonthFirstDay("yyyyMMdd"));
        } else {
            obj.setBeginDate(obj.getBeginDate().replaceAll("-", ""));
            obj.setEndDate(obj.getEndDate().replaceAll("-", ""));
        }
        return service.steelFre(obj);
    }

    @ResponseBody
    @Operation(summary = "分页查看记录")
    @PostMapping("/findByPage")
    public ResultData findDataByPage(@RequestBody FrsaHistoryReq data) {
        return service.findDataByPage(data);
    }

    @ResponseBody
    @Operation(summary = "分页查看记录")
    @PostMapping("/getDicPropCode")
    public ResultData getDicPropCode(@RequestBody RealDataDic data) {
        return service.getDicPropCode(data);
    }

}
